<?php
namespace api\xcx\controller;
use think\Cache;
use think\Loader;
use think\Db;
use think\Request;
use think\Controller;
use think\config;
/**
 *  Vip.php vip控制器
 *
 * @copyright			(C) 2014-2018 ShengTeng
 * @lastmodify			2018-05-21
 */
class Vip extends Base
{
    /**
 * @api {POST} Vip/vips vip信息获取
 * @apiVersion 1.0.1
 * @apiGroup Vip
 *
 * @apiSuccess {Int} code 返回码
 * @apiSuccess {String} message  提示信息
 * @apiSuccess {Object} data  返回数据
 *
 * @apiSuccessExample {json} Success-Response:
 *     HTTP/1.1 200 OK
 *     {
 *          "code":0,
 *          "message":"",
 *          "data":{
 *              "id"                //vipid
 *              "name"              // vip名称
 *              "price"             //vip价格
 *              "duration_time"     //vip月数
 *              "introduce"         //vip简介
 *              "is_recommend"      //是否推荐
 *          }
 *      }
 */
   public function vips(Request $request){
        $vip = Model('Vip');
        $res = $vip->sel_vip();
        if($res || $rs==[]){
            return json(returnAjax($res));
        }else{
            return json(returnAjax('','查询数据失败','-1'));
        }
   }

 /**
 * @api {POST} Vip/createVipOrder  创建vip订单
 * @apiVersion 1.0.0
 * @apiGroup Vip
 *
 * @apiParam {String} token 用户标识
 * @apiParam {Int} vipId    vipid
 * @apiParam {Int} staffId    员工id(非邀请就传0)
 * 
 * @apiSuccess {Int} code 返回码
 * @apiSuccess {String} message  提示信息
 * @apiSuccess {Object} data  返回数据
 *
 * @apiSuccessExample {json} Success-Response:
 *     HTTP/1.1 200 OK
 *     {
 *          "code":0,
 *          "message":"",
 *          "data":{
 *              oderNumber 订单号
 *          }
 *      }
 */ 
   public function createVipOrder(Request $request){
        $params=$request->param();
        // token
        $token = $this->checkParam($params['token'],'token',true);
        // vipId
        $vipId = $this->checkParam($params['vipId'],'vipId',true);
        // 验证staffId
        $staffId = $this->checkParam($params['staffId'],'staffId',true);
        // 查看用户是否存在
        $userid = $this->getUserId($token);
        $regionId = 1;
        // 获取用户信息,判断是否已是会员
        $user = Model('User');
        $userInfo = $user->getInfoById($userid);
        if($userInfo['userStatus']==2){
            return json(returnAjax('','您已是vip','1'));
        }
        // 根据vipid获取vip信息
        $vip = Model('vip');
        $vipInfo = $vip->sel_vip_id($vipId);
        if(!$vipInfo){
            return json(returnAjax('','未找到vip信息','1'));
        }
        $duration = $vipInfo['duration_time'];
        $amount = $vipInfo['price'];
        $vipNum = $vipInfo['vipNum'];
        $viporder = Model('Viporder');
        $res = $viporder->create_vip_order($userid,$amount,$duration,$vipId,$staffId,$regionId,$vipNum);
        if($res){
            return json(returnAjax($res));
        }else{
            return json(returnAjax('','无法生成订单','-1'));
        }
   }


 /**
 * @api {POST} Vip/reward  获取打赏金额
 * @apiVersion 1.0.0
 * @apiGroup Vip
 *
 * 
 * @apiSuccess {Int} code 返回码
 * @apiSuccess {String} message  提示信息
 * @apiSuccess {Object} data  返回数据
 *
 * @apiSuccessExample {json} Success-Response:
 *     HTTP/1.1 200 OK
 *     {
 *          "code":0,
 *          "message":"",
 *          "data":{
 *              "money": "20",//打赏金额
 *              "show_money": "很满意20元",//显示金额
 *              "reward_intro": "本仙女很满意"//底部说明
 *          }
 *      }
 */ 
public function reward(){
    $xcxinfo = Config::get('xcxinfo');
    $reward = $xcxinfo['reword_money'];
    $reward_mon = $xcxinfo['reword_show_money'];
    $reward_intro = $xcxinfo['reword_show_intro'];

    $rewwar_info = [];
    for( $i=0;$i<count($reward);$i++){
        $objects =(object)array();
        $objects->money = $reward[$i];
        $objects->show_money = $reward_mon[$i];
        $objects->reward_intro = $reward_intro[$i];
        array_push($rewwar_info,$objects);
    }
    return json(returnAjax($rewwar_info));
}




}
